package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 获取评论
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity getComments(@RequestParam(defaultValue = "1") Long page, @RequestParam(defaultValue = "10") Long pagesize) {

        PageResult pageResult = messagesService.getComments(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 获取点赞数
     *
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity getLikes(@RequestParam(defaultValue = "1") Long page, @RequestParam(defaultValue = "10") Long pagesize) {
        PageResult result = messagesService.getLikes(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 获取公告
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Long page, @RequestParam(defaultValue = "10") Long pagesize) {

        PageResult result = messagesService.getAnnouncements(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据环信id查询用户信息
     *
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity getUserinfo(String huanxinId) {
        UserInfoVo vo = messagesService.findByHxId(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 添加好友
     *
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String, Integer> params) {
        messagesService.addContacts(params);
        return ResponseEntity.ok(null);
    }

    /**
     * 获取好友列表
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity getContacts(Long page, Long pagesize) {
        PageResult result = messagesService.getContacts(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     *      获取被喜欢列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity getLoves(@RequestParam(defaultValue = "1") Long page,@RequestParam(defaultValue = "10") Long pagesize){
        PageResult result = messagesService.getLoves(page, pagesize);
        return ResponseEntity.ok(result);
    }
}
